﻿using System.Collections.Generic;
using Rhino.Etl.Core;
using Rhino.Etl.Core.Operations;

namespace EtlDemo.Rhino.JobCounts.Aggregates
{
    public class DefaultAffiliateRow : AbstractOperation
    {
        public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
        {
            // because IEnumerable<T> is not reentrant, we have to 
            // write some pedestrian-looking code

            int sum = 0;

            foreach (var row in rows)
            {
                sum += (int)row["JobCount"];
                yield return row;
            }

            var newrow = new Row();
            newrow["Affiliate"] = "default";
            newrow["JobCount"] = sum;

            yield return newrow;
        }
    }
}